/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ro.hex.remocadm.telnet.commands;

import java.io.IOException;
import java.util.Properties;
import java.util.StringTokenizer;
import ro.hex.remocadm.telnet.TelnetNotifier;
import ro.hex.remocadm.telnet.TelnetThread;

/**
 * Detector for the type of the server's operating system.
 *
 * @author Iulian Virtejanu
 */
public class GetServerTypeCommand extends TelnetThread {

    private String serverType;

    public GetServerTypeCommand(TelnetNotifier parent, Properties context) {
        super(parent, context);
    }

    @Override
    public void telnetDialog() throws IOException {
        writeLine("show media");
        String media = readUntil("> ");

        // search the markers that may say what the server type is.
        StringTokenizer st = new StringTokenizer(media, "\n");
        while (st.hasMoreTokens()) {
            String line = st.nextToken();
            line = line.trim();

            if (line.indexOf("dshow-tuner-channel") > -1) {
                serverType = "dx";
                break;
            }
            if (line.indexOf("v4l2-tuner-frequency") > -1) {
                serverType = "vl";
                break;
            }
        }
    }

    /**
     * Returns the type of the detected VLC server. If is not Linux, is
     * assumed to be Windows.
     * 
     * @return "vl" for VLC running on Linux, or "dx" for VLC running on Windows
     */
    public String getServerType() {
        return serverType;
    }

}
